import axios, { CancelToken } from "./config";
/**
 * @param {String} userName
 * @param {String} password
 */
 export const loginApi = (username, password) => axios.post("/users/login", {
  username,
  password
});

export const getCaptchaApi = () => axios.get("/users/getCaptcha");

export const verifyCaptcha = (captcha = "") => 
  axios.get("/users/verifyCaptcha",{
    params: {
      captcha
    },
  });
  /**
   * 
   * @param {String} page
   * @param {String} count 
   * @returns {Promise} 
   */
   export const getLoginLogApi = (componentInstance, page = 1, count = 15) => axios.get("/getloginlog", {
    params: {
      page,
      count,
    }
  })
  export const getQrcodeUrlApi = (sid) => axios.get("/users/getQrcode", {
    params: {
      sid
    }
  })
  export const wechatLoginApi = (wechatCode) => axios.get("/users/wechatLogin", {
    params: {
      wechatCode
    }
  })
  export const getSmsCode = (phoneNumber) =>
  axios.post("/sms/send", {
    phoneNumber,
  })
  export const updateUser = (data) => axios.post("/users/updateUser", data);
  export const getMenulistApi = () => axios.get("/permission/getMenuList")
  //获取学员列表
/**
 * 
 * @param {Number} page 页码
 * @param {Number} count 每页显示的数量
 * @param {String} classes 班级
 * @returns {Promise} 返回一个promise类型的方法
 */
export const getStuListApi = (page = 1, count = 10, classes = "") => axios.get("/students/getstulist", {
  params: {
    page,
    count,
    class: classes
  }
})
export const addStuApi = (data) => axios.post("/students/addstu", data)
export const updateStuApi = (data) => axios.post("/students/updatestu", data)
export const delStuApi = (sId) => axios.get("/students/delstu", {
  params: {
    sId
  }
})
export const getClassesApi = () => axios.get("/students/getclasses")
export const searchStuApi = (page, key, count) => {
  count = count || 10;
  key = key || "";
  page = page || 1;
  return axios.get("/students/searchstu", {
    params: {
      page,
      count,
      key
    }
  })
}
export const getOrderApi = (order_id) => axios.post("/order/get_order")
/**
 * 
 * @param {String} category_id 商品所在类目的id
 * @returns 
 */
export const getVipListApi = category_id => axios.get("/product/get_product", {
  params: {
    category_id
  }
})
export const preOrderApi = (product_id, quantity = 1) => axios.post("/order/pre_order", {
  product_id,
  quantity
})
/**
 * 
 * @param {String} order_id 订单的id
 * @returns 
 */
export const getOrderDetailApi = order_id => axios.post("/order/get_order", {
  order_id
})
export const getPayUrlApi = order_id => axios.post("/pay/payment", {
  order_id
})
export const queryPayResultApi = order_id => axios.get("/order/query_order_status", {
  params: {
    order_id
  }
})
export const getAllUsersApi = () => axios.get("/users/getAllUsers")
export const addUserApi = (username, password, nickname) => axios.post("/users/addUser", {
  username,
  password,
  nickname
})
export const expectDataApi = () => axios.get("/data/expect.json");
export const lineDataApi = () => axios.get("/data/rate.json");
export const taskDataApi = () => axios.get("/data/tarsk.json");